package leetcode_401_500;

import java.util.Arrays;

public class LeeCode_413 {
    public static void main(String[] args) {
        System.out.println(numberOfArithmeticSlices(new int[]{1, 2, 3, 5, 7}));
    }
    private static int numberOfArithmeticSlices(int[] nums) {
        int n = nums.length;
        int i = 0, ans = 0;
        while (i < n - 2){
            if (nums[i + 1] - nums[i] == nums[i + 2] - nums[i + 1]){
                int piff = nums[i + 1] - nums[i];
                int count = 3;
                i = i + 3;
                while (i < n && nums[i] - nums[i - 1] == piff){
                    count++;
                    i++;
                }
                for (int j = 1; j < count - 1; j++) {
                    ans += j;
                }
                i--;
            }else {
                i++;
            }
        }
        return ans;
    }
}
